package com.hrzyit.base.rx

import android.util.Log
import com.hrzyit.base.presenter.view.BaseView
import io.reactivex.Observer
import io.reactivex.disposables.Disposable

/**
 * Observer 基类
 * @author YangWei
 * @date 2019/4/10
 */
open class BaseObserver<T>(private var baseView: BaseView) : Observer<T> {
    override fun onError(e: Throwable) {
        Log.d("BaseObserver:", "OnError Message")
        // 当错误时执行
        baseView.hideLoading()
        if (e is BaseException) {
            baseView.onError(e.msg)
        }
    }

    override fun onSubscribe(d: Disposable) {
        Log.d("BaseObserver:", "onSubscribe Message")
    }

    override fun onComplete() {
        Log.d("BaseObserver:", "onComplete Message")
        // 当完成时执行
        // 关闭进度弹窗
        baseView.hideLoading()
    }

    override fun onNext(t: T) {
        Log.d("BaseObserver:", "onNext Message")
    }
}